# -*- coding: UTF-8 -*-
"""
人物 效果和Buff 的实现
By AnpyD
"""

import bs
from bsSpaz import *
import bsInternal
import bsUtils
import random
import os
import math
from game_stats import DATA_PATH
import member
import account_system


"""
Buff 死亡复仇 <Revenge>
"""
class Revenge(object):
    def __init__(self, node, multiple):
        self.node = node
        self.multiple = multiple
        self._timer = None
        self.last_death_pos = None
        self.spaz = self.node.getDelegate()
        bs.gameTimer(1000, self.work)

    def check_dead(self):
        if self.spaz.hitPoints <= 0 and ((self.spaz.lastPlayerHeldBy is not None and self.spaz.lastPlayerHeldBy.exists()) 
            or (self.spaz.lastPlayerAttackedBy is not None and self.spaz.lastPlayerAttackedBy.exists() 
            and bs.getGameTime() - self.spaz.lastAttackedTime < 4000)):
            try:
                self.last_death_pos = self.spaz.node.position
            except Exception:
                self._timer = None
            else:
                if not self.spaz.lastPlayerAttackedBy == self.spaz.getPlayer():
                    # work
                    self.drop_bomb()
                    self._timer = None

    def drop_bomb(self):
        bs.playSound(bs.getSound("activateBeep"), position=self.last_death_pos)
        bsUtils.PopupText(text="💀 死亡复仇",
                        color=(random.random(), random.random(), random.random()),
                        scale=0.8,
                        position=(self.node.position[0], self.node.position[1]-0.5, self.node.position[2])).autoRetain()
        if self.multiple == 1:
            bs.Bomb(position=(self.last_death_pos[0]+0.43, self.last_death_pos[1]+4, self.last_death_pos[2]-0.25),
                        velocity=(0,-6,0), sourcePlayer=self.spaz.getPlayer(), fuseTime=1000, modelScale=1.3,
                        bombType='sticky').autoRetain()

        elif self.multiple == 2:
            bs.Bomb(position=(self.last_death_pos[0]+0.43, self.last_death_pos[1]+4, self.last_death_pos[2]-0.25),
                        velocity=(0,-6,0), sourcePlayer=self.spaz.getPlayer(), fuseTime=2000, modelScale=1,
                        bombType='sticky').autoRetain()
            bs.Bomb(position=(self.last_death_pos[0]-0.43, self.last_death_pos[1]+4, self.last_death_pos[2]-0.25),
                        velocity=(0,-6,0), sourcePlayer=self.spaz.getPlayer(), fuseTime=2000, modelScale=1,
                        bombType='sticky').autoRetain()
            bs.Bomb(position=(self.last_death_pos[0], self.last_death_pos[1]+4, self.last_death_pos[2]+0.5),
                        velocity=(0,-6,0),sourcePlayer=self.spaz.getPlayer(), fuseTime=2000, modelScale=1,
                        bombType='sticky').autoRetain()

        elif self.multiple == 3:
            bs.Bomb(position=(self.last_death_pos[0]+0.43, self.last_death_pos[1]+3, self.last_death_pos[2]-0.25),
                        velocity=(0,-6,0), sourcePlayer=self.spaz.getPlayer(), fuseTime=1000, modelScale=1,
                        bombType='sticky').autoRetain()
            bs.Bomb(position=(self.last_death_pos[0]-0.43, self.last_death_pos[1]+3, self.last_death_pos[2]-0.25),
                        velocity=(0,-6,0), sourcePlayer=self.spaz.getPlayer(), fuseTime=1000, modelScale=1,
                        bombType='sticky').autoRetain()
            bs.Bomb(position=(self.last_death_pos[0], self.last_death_pos[1]+3, self.last_death_pos[2]+0.5),
                        velocity=(0,-6,0),sourcePlayer=self.spaz.getPlayer(), fuseTime=1000, modelScale=1,
                        bombType='sticky').autoRetain()
            bs.Bomb(position=(self.last_death_pos[0], self.last_death_pos[1]+4, self.last_death_pos[2]+0.5),
                        velocity=(0,-6,0),sourcePlayer=self.spaz.getPlayer(),
                        bombType='impact').autoRetain()

    def work(self):
        if self.spaz.isAlive():
            bs.playSound(bs.getSound("gunCocking"), position=self.last_death_pos)
            self._timer = bs.Timer(1, bs.Call(self.check_dead), repeat=True)

    
   

"""
环绕效果 Surround
"""
surround_type = ["bones", "bear", "ali", "b9000", "miku", "frosty", "RedCube"]

# Factory
class SurroundBallFactory(object):
    def __init__(self):
        self.bonesTex = bs.getTexture("bonesColor")
        self.bonesModel = bs.getModel("bonesHead")
        self.bearTex = bs.getTexture("bearColor")
        self.bearModel = bs.getModel("bearHead")
        self.aliTex = bs.getTexture("aliColor")
        self.aliModel = bs.getModel("aliHead")
        self.b9000Tex = bs.getTexture("cyborgColor")
        self.b9000Model = bs.getModel("cyborgHead")
        self.frostyTex = bs.getTexture("frostyColor")
        self.frostyModel = bs.getModel("frostyHead")
        self.cubeTex = bs.getTexture("eggTex1")
        self.cubeModel = bs.getModel("powerup")
        try:
            self.mikuModel = bs.getModel("operaSingerHead")
            self.mikuTex = bs.getTexture("operaSingerColor")
        except:
            bs.PrintException()

        self.ballMaterial = bs.Material()
        self.impactSound = bs.getSound("impactMedium")
        self.ballMaterial.addActions(actions=("modifyNodeCollision", "collide", False))

# Ball
class SurroundBall(bs.Actor):
    def __init__(self, spaz, shape="bones"):
        if spaz is None or not spaz.isAlive():
            return

        bs.Actor.__init__(self)

        self.spazRef = weakref.ref(spaz)

        factory = self.getFactory()

        s_model, s_texture = {
            "bones": (factory.bonesModel, factory.bonesTex),
            "bear": (factory.bearModel, factory.bearTex),
            "ali": (factory.aliModel, factory.aliTex),
            "b9000": (factory.b9000Model, factory.b9000Tex),
            "miku": (factory.mikuModel, factory.mikuTex),
            "frosty": (factory.frostyModel, factory.frostyTex),
            "RedCube": (factory.cubeModel, factory.cubeTex)
        }.get(shape, (factory.bonesModel, factory.bonesTex))

        self.node = bs.newNode("prop",
                               attrs={"model": s_model,
                                      "body": "sphere",
                                      "colorTexture": s_texture,
                                      "reflection": "soft",
                                      "modelScale": 0.5,
                                      "bodyScale": 0.1,
                                      "density": 0.1,
                                      "reflectionScale": [0.15],
                                      "shadowSize": 0.6,
                                      "position": spaz.node.position,
                                      "velocity": (0, 0, 0),
                                      "materials": [bs.getSharedObject("objectMaterial"), factory.ballMaterial]
                                      },
                                delegate=self)

        self.surroundTimer = None
        self.surroundRadius = 1.0
        self.angleDelta = math.pi / 12.0
        self.curAngle = random.random() * math.pi * 2.0
        self.curHeight = 0.0
        self.curHeightDir = 1
        self.heightDelta = 0.2
        self.heightMax = 1.0
        self.heightMin = 0.1
        self.initTimer(spaz.node.position)

    def getTargetPosition(self, spazPos):
        p = spazPos
        pt = (p[0] + self.surroundRadius * math.cos(self.curAngle),
              p[1] + self.curHeight,
              p[2] + self.surroundRadius * math.sin(self.curAngle))
        self.curAngle += self.angleDelta
        self.curHeight += self.heightDelta * self.curHeightDir
        if self.curHeight > self.heightMax or self.curHeight < self.heightMin:
            self.curHeightDir = -self.curHeightDir

        return pt

    def initTimer(self, p):
        self.node.position = self.getTargetPosition(p)
        self.surroundTimer = bs.Timer(30, bs.WeakCall(self.circleMove), repeat=True)

    def circleMove(self):
        spaz = self.spazRef()
        if spaz is None or not spaz.isAlive() or not spaz.node.exists():
            self.handleMessage(bs.DieMessage())
            return
        position = spaz.node.position
        pt = self.getTargetPosition(position)
        pn = self.node.position
        d = [pt[0] - pn[0], pt[1] - pn[1], pt[2] - pn[2]]
        speed = self.getMaxSpeedByDir(d)
        self.node.velocity = speed

    @staticmethod
    def getMaxSpeedByDir(direction):
        k = 7.0 / max((abs(x) for x in direction))
        return tuple(x * k for x in direction)

    def handleMessage(self, m):
        bs.Actor.handleMessage(self, m)
        if isinstance(m, bs.DieMessage):
            if self.surroundTimer is not None:
                self.surroundTimer = None
            self.node.delete()
        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

    def getFactory(cls):
        activity = bs.getActivity()
        if activity is None: 
            raise Exception("no current activity")
        try:
            return activity._sharedSurroundBallFactory
        except Exception:
            factory = activity._sharedSurroundBallFactory = SurroundBallFactory()
            return factory

class Burround(bs.Actor):
    def __init__(self, spaz, player, aid):
        bs.Actor.__init__(self)
        self.sourcePlayer = player
        self.spazRef = weakref.ref(spaz)
        self.spazNormalColor = spaz.node.color
        self.Decorations = []
        self.Enhancements = []
        self._powerScale = 1.0
        self._armorScale = 1.0
        self._lifeDrainScale = None
        self._damageBounceScale = None
        self._remoteMagicDamge = False
        self._MulitPunch = None
        self._AntiFreeze = 1.0
        self.fallWings = 0
        
        self.checkDeadTimer = None
        self._hasDead = False
        self.light = None

        flag = 0
        profiles = []
        profiles = self.sourcePlayer.getInputDevice()._getPlayerProfiles()  


        cl_str = self.sourcePlayer.get_account_id()
        clID = self.sourcePlayer.getInputDevice().getClientID()
        

        if profiles == [] or profiles == {}:
            profiles = bs.getConfig()['Player Profiles']

        if aid in account_system.get_data():
            if "surround" in account_system.get_data()[aid]["effects"]:
                if account_system.check_time(account_system.get_data()[aid]["effects"]["surround"]):
                    self.surround_ball = SurroundBall(spaz, shape=random.choice(surround_type))
                else:
                    account_system.del_effect(aid, "surround")

    def handleMessage(self, msg):

        if isinstance(msg, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(msg, bs.DieMessage):
            if hasattr(self, "surround_ball"):
                self.surround_ball = None

            if not self._hasDead:
                spaz = self.spazRef()
                if spaz is not None and spaz.isAlive() and spaz.node.exists():
                    spaz.node.color = self.spazNormalColor
                killer = spaz.lastPlayerAttackedBy if spaz is not None else None
                try:
                    if killer in (None,bs.Player(None)) or killer.actor is None or not killer.actor.exists() or killer.actor.hitPoints <= 0:killer = None
                except:killer = None
                
                self._hasDead = True
            
        bs.Actor.handleMessage(self, msg)



"""
高光效果 HighLight
"""
class HighLight(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(1, self.highlight)

    def highlight(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            self.light = bs.newNode("light", 
                        owner=self.spaz, 
                        attrs={"position":self.spaz.position, 
                                "color":(0, 0, 0), 
                                "volumeIntensityScale":0.6, 
                                "intensity":0.5,
                                "radius":0.25})

            self.spaz.connectAttr("position", self.light, "position")
            bs.animateArray(self.light, 'color', 3,
                            {0: (0, 0, 0), 500: (0.8, 0.8, 0.6)})
            bs.animateArray(self.spaz, 'color', 3,
                            {0: self.spaz.color, 500: (1.2, 1.3, 1.2), 1100: (1.9, 1.9, 1.9), 1600: (2.0, 2.0, 2.0)})
            bs.animateArray(self.spaz, 'highlight', 3,
                            {0: (3, 0, 0), 600: (0, 0, 0), 1100: (0, 0, 3), 1600: (3, 0, 0)}, True)



"""
脚印效果 FootPrint
"""
class FootPrint(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        self.last_pos = self.spaz.position

        bs.gameTimer(200, self.foot_print, True)

    def foot_print(self):
        if self.source_player.isAlive() and self.source_player.actor.isWalking() and self.spaz is not None and self.spaz.exists():
            pos = self.spaz.position
            pos2 = self.last_pos
            diff = (bs.Vector(pos[0] - pos2[0], 0.0, pos[2] - pos2[2]))
            dist = (diff.length())
            if dist > 0.2:
                locator = bs.newNode('locator',
                                attrs={
                                    'shape': 'circle',
                                    'position': pos,
                                    'color': self.spaz.color,
                                    'opacity': 1,
                                    'drawBeauty': False,
                                    'additive': False,
                                    'size': [0.15]
                                })
                bsUtils.animateArray(locator, 'size', 1, {
                    0: [0.15],
                    2500: [0.15],
                    3000: [0]
                })
                bs.gameTimer(3000, locator.delete)
                self.last_pos = self.spaz.position



"""
粒子效果 Sweat
"""
class Sweat(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.sweat, True)

    def sweat(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            vel = 4
            bs.emitBGDynamics(position=(self.spaz.torsoPosition[0] - 0.25 + random.random() * 0.5,
                                        self.spaz.torsoPosition[1] - 0.25 + random.random() * 0.5,
                                        self.spaz.torsoPosition[2] - 0.25 + random.random() * 0.8),
                                velocity=((-vel + (random.random() * (vel * 2))) + self.spaz.velocity[0] * 2,
                                        (-vel + (random.random() * (vel * 2))) + self.spaz.velocity[1] * 4,
                                        (-vel + (random.random() * (vel * 2))) + self.spaz.velocity[2] * 2),
                                count=5,
                                scale=0.8,
                                spread=0.2,
                                chunkType='sweat')

"""
粒子效果 Spark
"""
class Spark(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.spark, True)

    def spark(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            bs.emitBGDynamics(position=self.spaz.position, 
                                velocity=self.spaz.velocity, 
                                count=random.randint(6, 10), 
                                scale=0.8, 
                                spread=0.2,
                                chunkType="spark")



"""
粒子效果 Metal
"""
class Metal(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.metal, True)

    def metal(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            bs.emitBGDynamics(position=self.spaz.position, 
                                velocity=self.spaz.velocity, 
                                count=random.randint(2,8), 
                                scale=0.6, 
                                spread=0.2,
                                chunkType="metal")



"""
粒子效果 Ice
"""
class Ice(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.ice, True)

    def ice(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            bs.emitBGDynamics(position=self.spaz.position, 
                                velocity=self.spaz.velocity, 
                                count=random.randint(2,8), 
                                scale=0.6, 
                                spread=0.2,
                                chunkType="ice")



"""
粒子效果 Slime
"""
class Slime(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.slime, True)

    def slime(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            bs.emitBGDynamics(position=self.spaz.position, 
                                velocity=self.spaz.velocity, 
                                count=random.randint(2,8), 
                                scale=0.6, 
                                spread=0.2,
                                chunkType="Slime")



"""
彩虹效果 Rainbow
"""
class Rainbow(object):
    def __init__(self, spaz, _spaz):
        self.spaz = spaz

        self.source_player = _spaz

        bs.gameTimer(10, self.rainbow)

    def rainbow(self):
        if self.spaz is not None and self.spaz.exists() and self.source_player.isAlive():
            bs.animateArray(self.spaz, 'color', 3,
                            {0: (0, 0, 3), 600: (0, 3, 0), 1100: (3, 0, 0), 1600: (0, 0, 3)}, True)
            bs.animateArray(self.spaz, 'highlight', 3,
                            {0: (3, 0, 0), 600: (0, 0, 0), 1100: (0, 0, 3), 1600: (3, 0, 0)}, True)



"""
Buff 显示
"""
class Buff_Tag(object):
    def __init__(self, spaz, text):
        self.spaz = spaz

        self._text = text

        bs.gameTimer(random.randint(30, 80), self.text)

    def text(self):
        if self.spaz is not None and self.spaz.exists():
            bsUtils.PopupText(text=self._text,
                            color=(random.random(), random.random(), random.random()),
                            scale=0.8,
                            position=(self.spaz.position[0], self.spaz.position[1]-random.uniform(0, 1), self.spaz.position[2])).autoRetain()



"""
名称显示
"""
class Tag(object):
    def __init__(self, position=(0, 1, 0), owner=None, prefix=' - ', prefixColor=(1, 1, 1),
                 prefixAnim=None, prefixAnimate=True,type = 1):
        if prefixAnim is None:
            prefixAnim = {0: (1, 1, 1), 500: (0.5, 0.5, 0.5)}
        self.position = position
        self.owner = owner

        if type == 1:
            m = bs.newNode('math', owner=self.owner, attrs={'input1': (0, 1.90, 0), 'operation': 'add'})
        else:
            m = bs.newNode('math', owner=self.owner, attrs={'input1': (0, 1.35, 0), 'operation': 'add'})
        self.owner.connectAttr('position', m, 'input2')

        self._Text = bs.newNode('text',
                                owner=self.owner,
                                attrs={'text': prefix,  # prefix text
                                       'inWorld': True,
                                       'shadow': 1.2,
                                       'flatness': 1.0,
                                       'opacity': 0,
                                       'color': prefixColor,
                                       'scale': 0.008,
                                       'hAlign': 'center'})

        m.connectAttr('output', self._Text, 'position')

        if type == 1:
            bs.animate(self._Text, 'opacity', {0: 0.0, 500: 1, 1000: 0.0}, True)
        else:
            bs.animate(self._Text, 'opacity', {0: 0.0, 600: 1})  # smooth prefix spawn

        # animate prefix
        if prefixAnimate:
            bsUtils.animateArray(self._Text, 'color', 3, prefixAnim, True)  # animate prefix color


def __init__(self, color=(1, 1, 1), highlight=(0.5, 0.5, 0.5), character="Spaz", player=None, powerupsExpire=True):
    
    if player is None: 
        player = bs.Player(None)

    Spaz.__init__(self, color=color, highlight=highlight, character=character, sourcePlayer=player,
                  startInvincible=True, powerupsExpire=powerupsExpire)
    self.lastPlayerAttackedBy = None
    self.lastAttackedTime = 0
    self.lastAttackedType = None
    self.heldCount = 0
    self.lastPlayerHeldBy = None 
    self._player = player

    profiles = []
    profiles = self._player.getInputDevice()._getPlayerProfiles()

    if os.path.exists(DATA_PATH + "/account_information.json"):
        aid = str(self.sourcePlayer.get_account_id())
        try:
            _account_data = account_system.get_data()	
        except Exception:
            bs.printException()
        if aid in _account_data:
            level = account_system.get_level(aid)
            if level == 1:
                Tag(owner=self.node, 
                    prefix='进阶萌新',
                    prefixAnim={0: self._player.getTeam().color, 250: self._player.getTeam().color,250*2:self._player.getTeam().color,250*3:self._player.getTeam().color}, 
                    type=2)
            elif level == 2:
                Tag(owner=self.node, 
                    prefix=' 潜力萌新',
                    prefixAnim={0: self._player.getTeam().color, 250: self._player.getTeam().color,250*2:self._player.getTeam().color,250*3:self._player.getTeam().color}, 
                    type=2)
            elif level == 3:
                Tag(owner=self.node, 
                    prefix=' 磁暴步兵',
                    prefixAnim={0: self._player.getTeam().color, 250: self._player.getTeam().color,250*2:self._player.getTeam().color,250*3:self._player.getTeam().color}, 
                    type=2)
            elif level == 4:
                Tag(owner=self.node, 
                    prefix=' 狂暴杀手',
                    prefixAnim={0: self._player.getTeam().color, 250: self._player.getTeam().color,250*2:self._player.getTeam().color,250*3:self._player.getTeam().color}, 
                    type=2)
            elif level == 5:
                Tag(owner=self.node, 
                    prefix=' 无敌战神',
                    prefixAnim={0: self._player.getTeam().color, 250: self._player.getTeam().color,250*2:self._player.getTeam().color,250*3:self._player.getTeam().color}, 
                    type=2)

        if aid in member.AdminList:
            Tag(owner=self.node, 
                    prefix='#管理员#',
                    prefixAnim={0: (0.666,0.552,0.405), 250: (0.666,0.552,0.405),250*2:(0.666,0.552,0.405),250*3:(0.666,0.552,0.405)}, 
                    type=1)
            Sweat(spaz=self.node, _spaz=self.sourcePlayer)

        # 效果部分
        if aid in _account_data:
            if "sweat" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["sweat"]):
                    Sweat(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Sweat/水滴粒子 已过期！", "tip")
                    account_system.del_effect(aid, "sweat")
            if "rainbow" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["rainbow"]):
                    Rainbow(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Rainbow/彩虹 已过期！", "tip")
                    account_system.del_effect(aid, "rainbow")
            if "spark" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["spark"]):
                    Spark(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Spark/火花粒子 已过期！", "tip")
                    account_system.del_effect(aid, "spark")
            if "metal" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["metal"]):
                    Metal(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Metal/金属粒子 已过期！", "tip")
                    account_system.del_effect(aid, "metal")
            if "ice" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["ice"]):
                    Ice(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Ice/雪花粒子 已过期！", "tip")
                    account_system.del_effect(aid, "ice")
            if "slime" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["slime"]):
                    Slime(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 Slime/粘液粒子 已过期！", "tip")
                    account_system.del_effect(aid, "slime")
            if "footprint" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["footprint"]):
                    FootPrint(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 FootPrint/脚印 已过期！", "tip")
                    account_system.del_effect(aid, "footprint")
            if "highlight" in _account_data[aid]["effects"]:
                if account_system.check_time(_account_data[aid]["effects"]["highlight"]):
                    HighLight(spaz=self.node, _spaz=self.sourcePlayer)
                else:
                    account_system.account_message(aid, "系统提示：人物特效 HighLight/高光 已过期！", "tip")
                    account_system.del_effect(aid, "highlight")

            # buff 部分
            if "powerful" in _account_data[aid]["buffs"]:
                if account_system.check_time(_account_data[aid]["buffs"]["powerful"]["time"]):
                    self._punchPowerScale = _account_data[aid]["buffs"]["powerful"]["multiple"] + 0.2
                    buff_text = "力量提升 " + str((_account_data[aid]["buffs"]["powerful"]["multiple"]-1)*100) + "%"
                    bs.gameTimer(50, bs.Call(Buff_Tag, text=buff_text, spaz=self.node))
                else:
                    account_system.account_message(aid, "系统提示：人物Buff Powerful/力量提升 已过期！", "tip")
                    account_system.del_buff(aid, "powerful")
            if "protection" in _account_data[aid]["buffs"]:
                if account_system.check_time(_account_data[aid]["buffs"]["protection"]["time"]):
                    buff_text = "攻击防御 " + str((_account_data[aid]["buffs"]["protection"]["multiple"]-1)*100) + "%"
                    bs.gameTimer(50, bs.Call(Buff_Tag, text=buff_text, spaz=self.node))
                else:
                    account_system.account_message(aid, "系统提示：人物Buff Protection/攻击防御 已过期！", "tip")
                    account_system.del_buff(aid, "protection")
            if "revenge" in _account_data[aid]["buffs"]:
                if account_system.check_time(_account_data[aid]["buffs"]["revenge"]["time"]):
                    buff_text = "死亡复仇 倍数" + str(_account_data[aid]["buffs"]["revenge"]["multiple"])
                    Revenge(node=self.node, multiple=int(_account_data[aid]["buffs"]["revenge"]["multiple"]))
                    bs.gameTimer(50, bs.Call(Buff_Tag, text=buff_text, spaz=self.node))
                else:
                    account_system.account_message(aid, "系统提示：人物Buff Revenge/死亡复仇 已过期！", "tip")
                    account_system.del_buff(aid, "revenge")

        else:
            account_system.register(aid)
            account_system.account_message(aid, "系统提示:你已经被服务器注册！\n感谢游玩本服务器！", "tip")

    if player.exists():
        playerNode = bs.getActivity()._getPlayerNode(player)
        self.node.connectAttr('torsoPosition', playerNode, 'position')

    # 环绕效果
    self._burround = Burround(self, self.sourcePlayer, aid).autoRetain()



# 人物拳套力量改造
def _equipBoxingGloves(self):
    """
    Modif Punch Function
    """
    self.node.boxingGloves = 1
    try:
        account_id = self.node.getDelegate().getPlayer().get_account_id()
        _data = account_system.get_data()
        if account_id in _data:
            if "powerful" in _data[account_id]["buffs"]:
                if account_system.check_time(_data[account_id]["buffs"]["powerful"]["time"]):
                    self._punchPowerScale = _data[account_id]["buffs"]["powerful"]["multiple"] + 0.4
                else:
                    account_system.del_buff(account_id, "powerful")
                    account_system.account_message(account_id, "系统提示：人物Buff Powerful/力量提升 已过期！", "tip")
                    self._punchPowerScale = 1.4
            else:
                self._punchPowerScale = 1.4
        else:
            self._punchPowerScale = 1.4

        self._punchCooldown = 300
    except:
        # for bot
        self._punchPowerScale = 1.4
        self._punchCooldown = 300


# 人物拳套取消函数改造
def _glovesWearOff(self):
    self._punchCooldown = 400
    self._hasBoxingGloves = False

    try:
        account_id = self.node.getDelegate().getPlayer().get_account_id()
        _data = account_system.get_data()
        if account_id in _data:
            if "powerful" in _data[account_id]["buffs"]:
                if account_system.check_time(_data[account_id]["buffs"]["powerful"]["time"]):
                    self._punchPowerScale = _data[account_id]["buffs"]["powerful"]["multiple"]
                else:
                    account_system.del_buff(account_id, "powerful")
                    account_system.account_message(account_id, "系统提示：人物Buff Powerful/力量提升 已过期！", "tip")
                    self._punchPowerScale = 1.2
            else:
                self._punchPowerScale = 1.2
        else:
            self._punchPowerScale = 1.2

    except:
        # for bot
        self._punchPowerScale = 1.2

    if self.node.exists():
        bs.playSound(bs.Powerup.getFactory().powerdownSound,
                        position=self.node.position)
        self.node.boxingGloves = 0
        self.node.billboardOpacity = 0.0

# 人物攻击防御系数函数
def _protect_multiple(self):
    try:
        account_id = self.node.getDelegate().getPlayer().get_account_id()
        _data = account_system.get_data()
        if account_id in _data:
            if "protection" in _data[account_id]["buffs"]:
                if account_system.check_time(_data[account_id]["buffs"]["protection"]["time"]):
                    ple = 1 - (_data[account_id]["buffs"]["protection"]["multiple"] - 1)
                else:
                    account_system.del_buff(account_id, "protection")
                    account_system.account_message(account_id, "系统提示：人物Buff Protection/攻击防御 已过期！", "tip")
                    ple = 1
            else:
                ple = 1
        else:
            ple = 1

    except:
        # for bot
        ple = 1

    return ple